

import React, { Component }  from 'react';
import {
    View,
    Text,
    TextInput,
    StyleSheet,
} from 'react-native';
const Dimensions = require('Dimensions');
const { width } = Dimensions.get('window');
import {insertComment} from '../../../api/my';
import Toast from '../../../../node_modules/teaset/components/Toast/Toast';
import {setSpText,setHW} from '../../../component/ScreenUtil'
export default class AskQuestionComp extends Component {
    constructor(props) {
        super(props);
        this.state={
            inputText:'',//回复的输入框
            questionInputText:'',//向老师提问题的输入框
        }
    }
    render(){
        return(
            <View style={[styles.footerInput]}>
                <View style={styles.footInputBox}>
                    <TextInput style={styles.questionInput} 
                        ref="textInput1"
                        placeholder="请输入提问内容"
                        keyboardType={'default'}
                        value = {this.state.questionInputText}
                        onChangeText={(text) => this.setState({questionInputText:text})}
                        underlineColorAndroid='transparent'
                        />
                </View>
                <View style={styles.btn}>
                    <Text style={styles.btnText} onPress={()=>this.onButtonPress()}>向老师提问</Text>
                </View>
            </View>
        )
    }
    //   向老师提问
    onButtonPress(){
        let json={
            "COURSE_ID": this.props.dataInfor[0].ID,//课时id
            "USER_ID":global.ECourseConstant.userInfo.uuid,//用户id
            "TEACHER_ID":this.props.dataInfor[0].CREATOR,//老师id
            "COMMENT_CONTENT":this.state.questionInputText//评论内容
        }
        global.log(json,'json---------------')
        let emp= json.COMMENT_CONTENT.split(" ").join("").length === 0//全是空格
        if(!emp){
            insertComment(json).then(res=>{
                global.log("向老师提问了",res)
                this.refs.textInput1.blur()//自动去掉光标
                this.props.TabFun();//调用父组件的TabFun方法
                this.setState({questionInputText:''})//提问成功后清空
            })
        }else{
             Toast.message("请输入内容")
        }
    }
}
const styles = StyleSheet.create({
    // 提出问题
    footerInput:{
        flexDirection: 'row',
        justifyContent: 'space-between',
        paddingRight:0,
        position: 'absolute',
        width: width,
        bottom: 0,
        backgroundColor:'#fff',
    },
    footInputBox:{
        backgroundColor:'#fff',
        paddingTop:setHW(6),
        paddingBottom:setHW(6),
        paddingLeft:setHW(8),
        paddingRight:setHW(10),
        width:width - setHW(260),
        height: setHW(90),
    },
    questionInput:{
        width:width - setHW(280),
        height: setHW(90),
        backgroundColor:'#F5F5F5',
    },
    btn: {
        width: setHW(260),
        height: setHW(90),
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor:'#FF8A00',
    },
    btnText:{
        backgroundColor:'#FF8A00',
        color:'#fff',
        fontSize:setSpText(32),
    },
});
